import re

from django import template

def tag_params(token, param_re):
    try:
        tag_name, arg = token.contents.split(None, 1)
    except ValueError:
        raise template.TemplateSyntaxError("%r tag requires arguments" % token.contents.split()[0])
    m = re.search(param_re, arg)
    if not m:
        raise template.TemplateSyntaxError("%r tag had invalid arguments" % tag_name)
    return m.groups()


def render_string(request, tmpl, output):
    return template.loader.render_to_string(tmpl, output, context_instance=template.RequestContext(request)) 
